﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.Data;
using DevExpress.Web.Data;
using DevExpress.Data.Linq;

namespace Frame.Pages
{
    public abstract class BaseInfomationEditBasePage : BasePage
    {
        protected LinqServerModeDataSource LSMDSourceMain;
        protected DevExpress.Web.ASPxGridView.ASPxGridView gridView;
        /// <summary>
        /// 是否添加操作列
        /// </summary>
        protected virtual bool IsAddCommandColumn
        {
            get
            {
                return true;
            }
        }


        protected override void OnLoad( EventArgs e)
        {
            if (!IsPostBack && !IsCallback)
            {
                Frame.Global.GlobalFunctions.SetGridView(gridView, IsAddCommandColumn);
            }
            Frame.Global.GlobalFunctions.AddGridViewEvent(gridView);

            base.OnLoad( e);
        }

        
    }


    public abstract class FliterBIEditBasePage<T> : BaseInfomationEditBasePage where T : class
    {
        

        protected abstract Func<T, bool> FliterExpression
        {
            get;
        }

        protected override void OnLoad(EventArgs e)
        {
            if (FliterExpression !=null)
            {
                AddFliterSelectEvent(LSMDSourceMain, FliterExpression);
            }
            base.OnLoad(e);
        }


        protected void AddFliterSelectEvent(LinqServerModeDataSource Source, Func<T, bool> fun) 
        {
            Source.Selecting += new EventHandler<LinqServerModeDataSourceSelectEventArgs>
            (
                (sender, e) =>
                {
                    e.QueryableSource = Global.GlobalRunParms
                        .GetDefaultDataContext().GetTable<T>()
                        .Where(fun).AsQueryable();
                }
            );
        }

    }
}
